<?php

class Application_Model_DbTable_Report extends Zend_Db_Table_Abstract {

    public function getUserCount($day) {
        $db = $this->getAdapter();
        switch ($day) {
            case 2: {
                    $sql = "select count(id) userNum from uuch_user
	where DATE_FORMAT(datecreated, '%Y-%m-%e')=date_sub(curdate(),interval 2 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 1: {
                    $sql = "select  count(id) userNum from uuch_user
	where DATE_FORMAT(datecreated, '%Y-%m-%e')=date_sub(curdate(),interval 1 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 0: {
                    $sql = "select  count(id) userNum  from uuch_user
	where DATE_FORMAT(datecreated, '%Y-%m-%e')=curdate()";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 9: {
                    $sql = "select count(id)/7 userNum from uuch_user where datecreated<=date_add(curdate(),interval -2 day) and 
	datecreated>date_add(curdate(),interval -9 day) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 8: {
                    $sql = "select count(id)/7 userNum from uuch_user where datecreated<=date_add(curdate(),interval -1 day) and 
	datecreated>date_add(curdate(),interval -8 day) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 7: {
                    $sql = "select count(id)/7 userNum  from uuch_user where datecreated<=curdate() and 
	datecreated>date_add(curdate(),interval -7 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case -7: {
                    $sql = "select count(id) userNum  from uuch_user 
                    where DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 week)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 30: {
                    $sql = "select count(id) userNum  from uuch_user 
                    where DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 MONTH)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
        }
    }

    public function getStoreItemCount($day) {
        $db = $this->getAdapter();
        switch ($day) {
            case 2: {
                    $sql = "select count(id) storeitemNum from uuch_storeitem 
                    where DATE_FORMAT(dateInStore  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 1: {
                    $sql = "select count(id) storeitemNum from uuch_storeitem 
                    where DATE_FORMAT(dateInStore  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 0: {
                    $sql = "select count(id) storeitemNum from uuch_storeitem 
                    where DATE_FORMAT(dateInStore  , '%Y-%m-%e')=   curdate()";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 9: {
                    $sql = "select count(id)/7 storeitemNum from uuch_storeitem
                 where dateInStore <=date_add(curdate(),interval -2 day) and dateInStore >date_add(curdate(),interval -9 day) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 8: {
                    $sql = "select count(id)/7 storeitemNum from uuch_storeitem where dateInStore <=date_add(curdate(),interval -1 day) and 
	dateInStore >date_add(curdate(),interval -8 day)  ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 7: {
                    $sql = "select count(id)/7 storeitemNum from uuch_storeitem where dateInStore <=curdate() and 
	dateInStore >date_add(curdate(),interval -7 day)  ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -7: {
                    $sql = "select count(id) storeitemNum  from uuch_storeitem 
                        where DATE_FORMAT(dateInStore, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 week)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 30: {
                    $sql = "select count(id) storeitemNum  from uuch_storeitem 
                        where DATE_FORMAT(dateInStore, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 month)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
           case 12: {
                    $sql = "select count(id) storeitemNum from uuch_storeitem where DATE_FORMAT(dateInStore  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day) 
                        and userid not in (SELECT userid from uuch_storeitem where  dateInStore <date_add(curdate(),interval -2 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 11: {
                    $sql = "select count(id) storeitemNum from uuch_storeitem where DATE_FORMAT(dateInStore  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                        and userid not in (SELECT userid from uuch_storeitem where  dateInStore <date_add(curdate(),interval -1 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 10: {
                    $sql = "select count(id) storeitemNum from uuch_storeitem where DATE_FORMAT(dateInStore  , '%Y-%m-%e')=   curdate()
                        and userid not in (SELECT userid from uuch_storeitem where  dateInStore < curdate()  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 19: {
                    $sql = "select count(id)/7 storeitemNum from uuch_storeitem
                 where dateInStore <=date_add(curdate(),interval -2 day) and dateInStore >date_add(curdate(),interval -9 day) 
                 and userid not in (SELECT userid from uuch_storeitem where  dateInStore < date_add(curdate(),interval -9 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 18: {
                    $sql = "select count(id)/7 storeitemNum from uuch_storeitem where dateInStore <=date_add(curdate(),interval -1 day) and dateInStore >date_add(curdate(),interval -8 day) 
                        and userid not in (SELECT userid from uuch_storeitem where  dateInStore < date_add(curdate(),interval -8 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 17: {
                    $sql = "select count(id)/7 storeitemNum from uuch_storeitem where dateInStore <=curdate() and dateInStore >date_add(curdate(),interval -7 day)  
                        and userid not in (SELECT userid from uuch_storeitem where  dateInStore < date_add(curdate(),interval -7 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -17: {
                    $sql = "select count(id) storeitemNum  from uuch_storeitem 
                        where DATE_FORMAT(dateInStore, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)
                        and userid not in (SELECT userid from uuch_storeitem where  dateInStore < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 130: {
                    $sql = "select count(id) storeitemNum  from uuch_storeitem 
                        where DATE_FORMAT(dateInStore, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                        and userid not in (SELECT userid from uuch_storeitem where  dateInStore < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
           case 22: {
                    $sql = "select count(id) storeitemNum from uuch_storeitem where DATE_FORMAT(dateInStore  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day) 
                        and userid  in (SELECT userid from uuch_storeitem where  dateInStore <date_add(curdate(),interval -2 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 21: {
                    $sql = "select count(id) storeitemNum from uuch_storeitem where DATE_FORMAT(dateInStore  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                        and userid  in (SELECT userid from uuch_storeitem where  dateInStore <date_add(curdate(),interval -1 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 20: {
                    $sql = "select count(id) storeitemNum from uuch_storeitem where DATE_FORMAT(dateInStore  , '%Y-%m-%e')=   curdate()
                        and userid  in (SELECT userid from uuch_storeitem where  dateInStore < curdate()  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 29: {
                    $sql = "select count(id)/7 storeitemNum from uuch_storeitem
                 where dateInStore <=date_add(curdate(),interval -2 day) and dateInStore >date_add(curdate(),interval -9 day) 
                 and userid  in (SELECT userid from uuch_storeitem where  dateInStore < date_add(curdate(),interval -9 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 28: {
                    $sql = "select count(id)/7 storeitemNum from uuch_storeitem where dateInStore <=date_add(curdate(),interval -1 day) and dateInStore >date_add(curdate(),interval -8 day) 
                        and userid  in (SELECT userid from uuch_storeitem where  dateInStore < date_add(curdate(),interval -8 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 27: {
                    $sql = "select count(id)/7 storeitemNum from uuch_storeitem where dateInStore <=curdate() and dateInStore >date_add(curdate(),interval -7 day)  
                        and userid  in (SELECT userid from uuch_storeitem where  dateInStore < date_add(curdate(),interval -7 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -27: {
                    $sql = "select count(id) storeitemNum  from uuch_storeitem 
                        where DATE_FORMAT(dateInStore, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)
                        and userid  in (SELECT userid from uuch_storeitem where  dateInStore < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 230: {
                    $sql = "select count(id) storeitemNum  from uuch_storeitem 
                        where DATE_FORMAT(dateInStore, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                        and userid in (SELECT userid from uuch_storeitem where  dateInStore < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
        }
    }

    public function getOrderCount($day) {
        $db = $this->getAdapter();
        switch ($day) {
            case 2: {
                    $sql = "select count(id) orderNum  from uuch_order where status>=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 1: {
                    $sql = "select count(id) orderNum  from uuch_order where status>=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 0: {
                    $sql = "select count(id) orderNum  from uuch_order where status>=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  curdate()";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 9: {
                    $sql = "select count(*)/7 from uuch_order where status>=1 and dateCreated <=date_add(curdate(),interval -2 day) and 
	dateCreated  >date_add(curdate(),interval -9 day) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 8: {
                    $sql = "select  count(*)/7 from uuch_order where status>=1 and dateCreated <=date_add(curdate(),interval -1 day) and 
	dateCreated  >date_add(curdate(),interval -8 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 7: {
                    $sql = "select count(*)/7 from uuch_order 
                        where status>=1 and dateCreated <=curdate() and 	
                        dateCreated  >date_add(curdate(),interval -7 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -7: {
                    $sql = "select count(id) orderNum  from uuch_order
                    where status>=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 week)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 30: {
                    $sql = "select count(id) orderNum  from uuch_order
                    where status>=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 month)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
           case 12: {
                    $sql = "select count(id) orderNum  from uuch_order where status>=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)
                        and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -2 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 11: {
                    $sql = "select count(id) orderNum  from uuch_order where status>=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                        and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -1 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 10: {
                    $sql = "select count(id) orderNum  from uuch_order where status>=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  curdate()
                        and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated < curdate() GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 19: {
                    $sql = "select count(*)/7 from uuch_order where status>=1 and dateCreated <=date_add(curdate(),interval -2 day) and 
	dateCreated  >date_add(curdate(),interval -9 day) and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -9 day) GROUP BY userid) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 18: {
                    $sql = "select  count(*)/7 from uuch_order where status>=1 and dateCreated <=date_add(curdate(),interval -1 day) and 
	dateCreated  >date_add(curdate(),interval -8 day) and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -8 day) GROUP BY userid) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 17: {
                    $sql = "select count(*)/7 from uuch_order where status>=1 and dateCreated <=curdate() and dateCreated  >date_add(curdate(),interval -7 day)
                        and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -7 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -17: {
                    $sql = "select count(id) orderNum  from uuch_order
                    where status>=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)
                     and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 130: {
                    $sql = "select count(id) orderNum  from uuch_order
                    where status>=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                    and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 22: {
                    $sql = "select count(id) orderNum  from uuch_order where status>=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)
                        and userId in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -2 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 21: {
                    $sql = "select count(id) orderNum  from uuch_order where status>=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                        and userId in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -1 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 20: {
                    $sql = "select count(id) orderNum  from uuch_order where status>=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  curdate()
                        and userId in (SELECT userId from uuch_order where status>=1 and dateCreated < curdate() GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 29: {
                    $sql = "select count(*)/7 from uuch_order where status>=1 and dateCreated <=date_add(curdate(),interval -2 day) and 
	dateCreated  >date_add(curdate(),interval -9 day) and userId in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -9 day) GROUP BY userid) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 28: {
                    $sql = "select  count(*)/7 from uuch_order where status>=1 and dateCreated <=date_add(curdate(),interval -1 day) and 
	dateCreated  >date_add(curdate(),interval -8 day) and userId in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -8 day) GROUP BY userid) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 27: {
                    $sql = "select count(*)/7 from uuch_order where status>=1 and dateCreated <=curdate() and dateCreated  >date_add(curdate(),interval -7 day)
                        and userId in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -7 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -27: {
                    $sql = "select count(id) orderNum  from uuch_order
                    where status>=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)
                     and userId in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 230: {
                    $sql = "select count(id) orderNum  from uuch_order
                    where status>=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                    and userId in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
        }
    }

    public function getOrderPriceCount($day) {
        $db = $this->getAdapter();
        switch ($day) {
            case 2: {
                    $sql = "select sum(sum)  from uuch_order where status>=1 and status != 10 and status != 11 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 1: {
                    $sql = "select sum(sum) from uuch_order where status>=1 and status != 10 and status != 11 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 0: {
                    $sql = "select sum(sum)  from uuch_order where status>=1 and status != 10 and status != 11 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  curdate()";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 9: {
                    $sql = "select sum(sum)/7 from uuch_order where status>=1 and status != 10 and status != 11 and dateCreated <=date_add(curdate(),interval -2 day) and 
	dateCreated  >date_add(curdate(),interval -9 day) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 8: {
                    $sql = "select sum(sum)/7 from uuch_order where status>=1 and status != 10 and status != 11 and dateCreated <=date_add(curdate(),interval -1 day) and 
	dateCreated  >date_add(curdate(),interval -8 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 7: {
                    $sql = "select sum(sum)/7 from uuch_order 
                        where status>=1 and status != 10 and status != 11 and dateCreated <=curdate() and 	
                        dateCreated  >date_add(curdate(),interval -7 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -7: {
                    $sql = "select sum(sum) from uuch_order
                    where status>=1 and status != 10 and status != 11 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 week)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 30: {
                    $sql = "select sum(sum) from uuch_order
                    where status>=1 and status != 10 and status != 11 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 month)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 12: {
                    $sql = "select sum(sum)  from uuch_order where status>=1 and status != 10 and status != 11 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)
                        and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(curdate(),interval -2 day)  GROUP BY userid)";
                    
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 11: {
                    $sql = "select sum(sum) from uuch_order where status>=1 and status != 10 and status != 11 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                        and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated < date_add(curdate(),interval -1 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 10: {
                    $sql = "select sum(sum)  from uuch_order where status>=1 and  status != 10 and status != 11 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  curdate()
                        and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated <curdate()  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 19: {
                    $sql = "select sum(sum)/7 from uuch_order where status>=1 and status != 10 and status != 11 and dateCreated <=date_add(curdate(),interval -2 day) and dateCreated  >date_add(curdate(),interval -9 day) 
                        and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(curdate(),interval -9 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 18: {
                    $sql = "select sum(sum)/7 from uuch_order where status>=1 and status != 10 and status != 11 and dateCreated <=date_add(curdate(),interval -1 day) and dateCreated  >date_add(curdate(),interval -8 day)
                       and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(curdate(),interval -8 day)  GROUP BY userid) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 17: {
                    $sql = "select sum(sum)/7 from uuch_order where status>=1 and status != 10 and status != 11 and dateCreated <=curdate() and dateCreated  >date_add(curdate(),interval -7 day)
                        and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(curdate(),interval -7 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -17: {
                    $sql = "select sum(sum) from uuch_order
                    where status>=1 and status != 10 and status != 11 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)
                    and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 130: {
                    $sql = "select sum(sum) from uuch_order
                    where status>=1 and status != 10 and status != 11 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                    and userId not in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 22: {
                    $sql = "select sum(sum)  from uuch_order where status>=1 and status != 10 and status != 11 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)
                        and userId in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(curdate(),interval -2 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 21: {
                    $sql = "select sum(sum) from uuch_order where status>=1 and status != 10 and status != 11 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                        and userId in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(curdate(),interval -1 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 20: {
                    $sql = "select sum(sum)  from uuch_order where status>=1 and status != 10 and status != 11 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  curdate()
                        and userId in (SELECT userId from uuch_order where status>=1 and dateCreated <curdate()  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 29: {
                    $sql = "select sum(sum)/7 from uuch_order where status>=1 and status != 10 and status != 11 and dateCreated <=date_add(curdate(),interval -2 day) and dateCreated  >date_add(curdate(),interval -9 day) 
                        and userId in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(curdate(),interval -9 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 28: {
                    $sql = "select sum(sum)/7 from uuch_order where status>=1 and status != 10 and status != 11 and dateCreated <=date_add(curdate(),interval -1 day) and dateCreated  >date_add(curdate(),interval -8 day)
                       and userId in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(curdate(),interval -8 day)  GROUP BY userid) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 27: {
                    $sql = "select sum(sum)/7 from uuch_order where status>=1 and status != 10 and status != 11 and dateCreated <=curdate() and dateCreated  >date_add(curdate(),interval -7 day)
                        and userId in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(curdate(),interval -7 day)  GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -27: {
                    $sql = "select sum(sum) from uuch_order
                    where status>=1 and status != 10 and status != 11 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)
                    and userId in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 230: {
                    $sql = "select sum(sum) from uuch_order
                    where status>=1 and status != 10 and status != 11 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                    and userId in (SELECT userId from uuch_order where status>=1 and dateCreated <date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
        }
    }

    public function getStoreItemWeightCount($day) {
        $db = $this->getAdapter();
        switch ($day) {
            case 2: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and status >=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 1: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and status >=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 0: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and status >=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=   curdate()";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 9: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/7000 FROM `uuch_waybill` 
                 where status >=1 and dateCreated <=date_add(curdate(),interval -2 day) and dateCreated >date_add(curdate(),interval -9 day) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 8: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/7000 FROM `uuch_waybill` 
                 where status >=1 and dateCreated <=date_add(curdate(),interval -1 day) and dateCreated >date_add(curdate(),interval -8 day)  ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 7: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/7000 FROM `uuch_waybill` 
                 where status >=1 and dateCreated <=curdate() and dateCreated >date_add(curdate(),interval -7 day) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -7: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM uuch_waybill where status >=1 and
                        DATE_FORMAT(dateCreated, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 30: {
                     $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM uuch_waybill where status >=1 and
                        DATE_FORMAT(dateCreated, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
           case 12: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM uuch_waybill 
                    where status >=1 and status >=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)
                    and userId not in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -2 day) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 11: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                    and userId not in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -1 day) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 10: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=   curdate()
                    and userId not in (select userId from uuch_waybill where dateCreated<curdate() GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 19: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/7000 FROM `uuch_waybill` 
                 where status >=1 and dateCreated <=date_add(curdate(),interval -2 day) and dateCreated >date_add(curdate(),interval -9 day) 
                 and userId not in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -9 day) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 18: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/7000 FROM `uuch_waybill` 
                 where status >=1 and dateCreated <=date_add(curdate(),interval -1 day) and dateCreated >date_add(curdate(),interval -8 day)  
                 and userId not in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -8 day) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 17: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/7000 FROM `uuch_waybill` 
                 where status >=1 and dateCreated <=curdate() and dateCreated >date_add(curdate(),interval -7 day) 
                 and userId not in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -7 day) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -17: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM uuch_waybill where status >=1 and
                        DATE_FORMAT(dateCreated, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)
                        and userId not in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -1 week) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 130: {
                     $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM uuch_waybill where status >=1 and
                        DATE_FORMAT(dateCreated, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                        and userId not in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -1 month) GROUP BY userId)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
           case 22: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)
                    and userId in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -2 day) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 21: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                    and userId  in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -1 day) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 20: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and DATE_FORMAT(dateCreated  , '%Y-%m-%e')=   curdate()
                    and userId  in (select userId from uuch_waybill where dateCreated<curdate() GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 29: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/7000 FROM `uuch_waybill` 
                 where status >=1 and dateCreated <=date_add(curdate(),interval -2 day) and dateCreated >date_add(curdate(),interval -9 day) 
                 and userId  in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -9 day) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 28: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/7000 FROM `uuch_waybill` 
                 where status >=1 and dateCreated <=date_add(curdate(),interval -1 day) and dateCreated >date_add(curdate(),interval -8 day)  
                 and userId  in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -8 day) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 27: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/7000 FROM `uuch_waybill` 
                 where status >=1 and dateCreated <=curdate() and dateCreated >date_add(curdate(),interval -7 day) 
                 and userId  in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -7 day) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -27: {
                    $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM uuch_waybill where status >=1 and
                        DATE_FORMAT(dateCreated, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)
                        and userId  in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -1 week) GROUP BY userId )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 230: {
                     $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM uuch_waybill where status >=1 and
                        DATE_FORMAT(dateCreated, '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                        and userId  in (select userId from uuch_waybill where dateCreated<date_add(curdate(),interval -1 month) GROUP BY userId)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
        }
    }

    public function getExpressOrderCount($day) {
        $db = $this->getAdapter();
        switch ($day) {
            case 2: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 1: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 0: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  curdate()";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 9: {
                    $sql = "select count(*)/7 from uuch_waybill where status >=1 and datePaid <=date_add(curdate(),interval -2 day) and 
	datePaid  >date_add(curdate(),interval -9 day) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 8: {
                    $sql = "select  count(*)/7 from uuch_waybill where status >=1 and datePaid <=date_add(curdate(),interval -1 day) and 
	datePaid  >date_add(curdate(),interval -8 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 7: {
                    $sql = "select count(*)/7 from uuch_waybill 
                        where status >=1 and datePaid <=curdate() and 	
                        datePaid  >date_add(curdate(),interval -7 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -7: {
                    $sql = "select count(id) orderNum  from uuch_waybill
                    where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 week)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 30: {
                    $sql = "select count(id) orderNum  from uuch_waybill
                    where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 month)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
           case 12: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -2 day) GROUP BY userid) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 11: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -1 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 10: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  curdate()
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < curdate() GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 19: {
                    $sql = "select count(*)/7 from uuch_waybill where status >=1 and datePaid <=date_add(curdate(),interval -2 day) and datePaid  >date_add(curdate(),interval -9 day) 
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -9 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 18: {
                    $sql = "select  count(*)/7 from uuch_waybill where status >=1 and datePaid <=date_add(curdate(),interval -1 day) and datePaid  >date_add(curdate(),interval -8 day)
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -8 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 17: {
                    $sql = "select count(*)/7 from uuch_waybill where status >=1 and datePaid <=curdate() and datePaid  >date_add(curdate(),interval -7 day)
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -7 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -17: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 130: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
           case 22: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -2 day) GROUP BY userid) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 21: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -1 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 20: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  curdate()
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < curdate() GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 29: {
                    $sql = "select count(*)/7 from uuch_waybill where status >=1 and datePaid <=date_add(curdate(),interval -2 day) and datePaid  >date_add(curdate(),interval -9 day) 
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -9 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 28: {
                    $sql = "select  count(*)/7 from uuch_waybill where status >=1 and datePaid <=date_add(curdate(),interval -1 day) and datePaid  >date_add(curdate(),interval -8 day)
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -8 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 27: {
                    $sql = "select count(*)/7 from uuch_waybill where status >=1 and datePaid <=curdate() and datePaid  >date_add(curdate(),interval -7 day)
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -7 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -27: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week)
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 week) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 230: {
                    $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
        }
    }

    public function getExpressOrderPriceCount($day) {
        $db = $this->getAdapter();
        switch ($day) {
            case 2: {
                    $sql = "select sum(SHIPMONEY)  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 1: {
                    $sql = "select sum(SHIPMONEY) from uuch_waybill where status >=1
                        and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 0: {
                    $sql = "select sum(SHIPMONEY)  from uuch_waybill where status >=1
                        and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  curdate()";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 9: {
                    $sql = "select sum(SHIPMONEY)/7 from uuch_waybill where status >=1
                            and datePaid <=date_add(curdate(),interval -2 day) and 
	datePaid  >date_add(curdate(),interval -9 day) ";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 8: {
                    $sql = "select sum(SHIPMONEY)/7 from uuch_waybill where status >=1
                        and datePaid <=date_add(curdate(),interval -1 day) and 
	datePaid  >date_add(curdate(),interval -8 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 7: {
                    $sql = "select sum(SHIPMONEY)/7 from uuch_waybill 
                        where status >=1 and datePaid <=curdate() and 	
                        datePaid  >date_add(curdate(),interval -7 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -7: {
                    $sql = "select sum(SHIPMONEY) from uuch_waybill
                    where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')= DATE_ADD(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ) , INTERVAL -1 week )";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 30: {
                    $sql = "select sum(SHIPMONEY) from uuch_waybill
                    where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1
DAY ),interval -1 month)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 12: {
                    $sql = "select sum(SHIPMONEY)  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)
                         and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -2 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 11: {
                    $sql = "select sum(SHIPMONEY) from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -1 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 10: {
                    $sql = "select sum(SHIPMONEY)  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  curdate()
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < curdate() GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 19: {
                    $sql = "select sum(SHIPMONEY)/7 from uuch_waybill where status >=1 and datePaid <=date_add(curdate(),interval -2 day) and datePaid  >date_add(curdate(),interval -9 day) 
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -9 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 18: {
                    $sql = "select sum(SHIPMONEY)/7 from uuch_waybill where status >=1 and datePaid <=date_add(curdate(),interval -1 day) and datePaid  >date_add(curdate(),interval -8 day)
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -8 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 17: {
                    $sql = "select sum(SHIPMONEY)/7 from uuch_waybill where status >=1 and datePaid <=curdate() and datePaid  >date_add(curdate(),interval -7 day)
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -7 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -17: {
                    $sql = "select sum(SHIPMONEY) from uuch_waybill where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')= DATE_ADD(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ) , INTERVAL -1 week )
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < DATE_ADD(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ) , INTERVAL -1 week ) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 130: {
                    $sql = "select sum(SHIPMONEY) from uuch_waybill where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                        and userId not in (SELECT userId from uuch_waybill where status>=1 and datePaid < DATE_ADD(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ) , INTERVAL -1 month ) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
            case 22: {
                    $sql = "select sum(SHIPMONEY)  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -2 day)
                         and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -2 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 21: {
                    $sql = "select sum(SHIPMONEY) from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -1 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 20: {
                    $sql = "select sum(SHIPMONEY)  from uuch_waybill where status >=1 and DATE_FORMAT(datePaid  , '%Y-%m-%e')=  curdate()
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < curdate() GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 29: {
                    $sql = "select sum(SHIPMONEY)/7 from uuch_waybill where status >=1 and datePaid <=date_add(curdate(),interval -2 day) and datePaid  >date_add(curdate(),interval -9 day) 
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -9 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 28: {
                    $sql = "select sum(SHIPMONEY)/7 from uuch_waybill where status >=1 and datePaid <=date_add(curdate(),interval -1 day) and datePaid  >date_add(curdate(),interval -8 day)
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -8 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 27: {
                    $sql = "select sum(SHIPMONEY)/7 from uuch_waybill where status >=1 and datePaid <=curdate() and datePaid  >date_add(curdate(),interval -7 day)
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(curdate(),interval -7 day) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case -27: {
                    $sql = "select sum(SHIPMONEY) from uuch_waybill where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')= DATE_ADD(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ) , INTERVAL -1 week )
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < DATE_ADD(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ) , INTERVAL -1 week ) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 230: {
                    $sql = "select sum(SHIPMONEY) from uuch_waybill where status >=1 and DATE_FORMAT(datecreated , '%Y-%m-%e')=  date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month)
                        and userId in (SELECT userId from uuch_waybill where status>=1 and datePaid < date_add(DATE_ADD( CURDATE( ) , INTERVAL -1 DAY ),interval -1 month) GROUP BY userid)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
        }
    }

    public function getStoreWeightCount($day)
    {
        $db = $this->getAdapter();

        switch ($day) {
            case 0: {
                    $sql = "select sum(weight)/1000 from uuch_storeitem where  DATE_FORMAT(dateInStore  , '%Y-%m-%e')=  curdate()";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }

            case 1: {
                    $sql = "select sum(weight)/1000 from uuch_storeitem where DATE_FORMAT(dateInStore  , '%Y-%m-%e')=  date_add(curdate(),interval -1 day)";
                    $result = $db->query($sql);
                    return $result->fetchColumn();
                }
        }
    }
    /**
     * 渠道商排行
     */
    public function topChannel($start,$end){
        if(!$start){
            $start = "2010-01-01";
        }
        if(!$end){
            $end = date("Y-m-d");
        }
        $db = $this->getAdapter();
        $sql = "SELECT w.channer, e.name, COUNT( * ) AS num, SUM( w.shipMoney ) AS sum
            FROM uuch_waybill w
            LEFT JOIN uuch_expressChannel e ON e.id = w.channer
            WHERE w.status >0 and w.dateCreated >= '".$start." 00:00:00' and w.dateCreated <= '".$end." 23:59:59' 
            GROUP BY w.channer
            ORDER BY num DESC,sum DESC; ";
        $list = $db->query($sql);
        return $list->fetchAll();
    }
    
     /**
     * $start 开始时间
     * $end  结束时间
     * $type  "all" 所有用户 "new" 新用户 "order" 老用户
     * $cid   所在国家
     * 获取代购数量
     */
    public function shopBuyCount($start, $end, $type,$cid = null){
        if($type == "all"){
            if($cid){
                $sql = "SELECT count(*) FROM uuch_order o left join uuch_user u on u.id = o.userid WHERE u.cityId = ".$cid." and o.status >= 1 AND o.dateCreated >= '".$start."' AND o.dateCreated <= '".$end."'";        
            }else{
                $sql = "SELECT count(*) FROM uuch_order WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."'";
            }
        }else if($type == "new"){
            if($cid){
                $sql = "SELECT count(*) FROM uuch_order o left join uuch_user u on u.id = o.userid WHERE u.cityId = ".$cid." and o.status >= 1 AND o.dateCreated >= '".$start."' AND o.dateCreated <= '".$end."' 
                    AND o.userId NOT IN (SELECT o.userId From uuch_order o where o.status >= 1 and o.dateCreated < '".$start."' GROUP BY o.userid)";
            }else{
                $sql = "SELECT count(*) FROM uuch_order WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."' 
                    AND userId NOT IN (SELECT userId From uuch_order where status >= 1 and dateCreated < '".$start."' GROUP BY userid)";
            }
        }else if($type == "order"){
            $sql = "SELECT count(*) FROM uuch_order WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."' 
            AND userId IN (SELECT userId FROM uuch_order WHERE status >= 1 AND dateCreated < '".$start."' GROUP BY userid)";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    } 

     /**
     * $start 开始时间
     * $end  结束时间
     * $type  "all" 所有用户 "new" 新用户 "order" 老用户 
     * $cid   所在国家
     * 获取代购金额
     */
    public function shopBuyMoney($start, $end, $type, $cid = null){
        if($type == "all"){
            $sql = "SELECT sum(sum) FROM uuch_order WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."'";
        }else if($type == "new"){
            if($cid){
                $sql = "SELECT sum(sum) FROM uuch_order o left join uuch_user u on o.userId = u.id WHERE o.status >= 1 AND o.dateCreated >= '".$start."' AND o.dateCreated <= '".$end."' AND u.cityId = ".$cid."
                    AND o.userId NOT IN (SELECT o.userId FROM uuch_order o where o.status >=1 and o.dateCreated < '".$start."' GROUP BY o.userId)";
            }else{
                $sql = "SELECT sum(sum) FROM uuch_order WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."' 
                    AND userId NOT IN (SELECT userId FROM uuch_order where status >= 1 and dateCreated < '".$start."' GROUP BY userid)";
            }
        }else if($type == "order"){
            $sql = "SELECT sum(sum) FROM uuch_order WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."' 
                AND userId IN (SELECT userId FROM uuch_order where status >= 1 and dateCreated < '".$start."' GROUP BY userid)";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
     /**
     * $start 开始时间
     * $end  结束时间
     * $type  "all" 所有用户 "new" 新用户 "order" 老用户 
      * $cid   所在国家
     * 获取代购会员数
     */
    public function shopBuyMemberCount($start,$end,$type,$cid=null){
        if($type == "all"){
            $sql = "SELECT count(*) as memberCount from (SELECT count(userId) FROM uuch_order WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."' GROUP BY userId) as user";
        }else if($type == "new"){
            if($cid){
                $sql = "SELECT count(*) as memberCount from (SELECT count(o.userId) FROM uuch_order o left join uuch_user u on u.id = o.userId WHERE u.cityId = ".$cid." and o.status >= 1 
                    and o.dateCreated >= '".$start."' AND o.dateCreated <= '".$end."' and o.userId NOT IN (SELECT o.userId from uuch_order o where o.status >= 1 
                    and o.dateCreated < '".$start."' GROUP BY o.userid) GROUP BY o.userId) as user";
            }else{
                $sql = "SELECT count(*) as memberCount from (SELECT count(userId) FROM uuch_order WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."' 
                    AND userId NOT IN (SELECT userId From uuch_order where status >= 1 and dateCreated < '".$start."' GROUP BY userid) GROUP BY userId) as user";
            }
        }else if($type == "order"){
            $sql = "SELECT count(*) as memberCount from (SELECT count(userId) FROM uuch_order WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."' 
                AND userId IN (SELECT userId From uuch_order where status >= 1 and dateCreated < '".$start."' GROUP BY userid)  GROUP BY userId) as user";
        }        
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    /**
     * $start 开始时间
     * $end  结束时间
     * $cid   所在国家
     * 注册用户数
     */
    public function registeredCount($start,$end,$cid = null){
        if($cid){
            $sql = "select count(*) userNum  from uuch_user
                where cityId = ".$cid." and (userType is null or userType = '0' or userType = '') and dateCreated >= '".$start."' and dateCreated <= '".$end."'";
        }else{
            $sql = "select count(*) userNum  from uuch_user
                where (userType is null or userType = '0' or userType = '') and dateCreated >= '".$start."' and dateCreated <= '".$end."'";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    /**
     * $start 开始时间
     * $end  结束时间
     * $type  "all" 所有用户 "new" 新用户 "order" 老用户 
     * $cid   所在国家
     * 包裹入库数
     */
    public function storeItemNum($start,$end,$type,$cid = null){
        if($type == "all"){
            $sql = "select count(id) storeitemNum from uuch_storeitem 
                    where dateInStore >= '".$start."' AND dateInStore <= '".$end."' AND isdelete != 1";
        }else if($type == "new"){
            if($cid){
                $sql = "select count(s.id) storeitemNum from uuch_storeitem s left join uuch_user u on u.id = s.userId where u.cityId = ".$cid." and s.dateInStore >= '".$start."' AND s.dateInStore <= '".$end."' AND s.isdelete != 1
                        and s.userid not in (SELECT s.userid from uuch_storeitem s where  s.dateInStore < '".$start."' GROUP BY s.userid)";
            }else{
                $sql = "select count(id) storeitemNum from uuch_storeitem where dateInStore >= '".$start."' AND dateInStore <= '".$end."' AND isdelete != 1
                        and userid not in (SELECT userid from uuch_storeitem where  dateInStore < '".$start."' GROUP BY userid)";
            }
        }else if($type == "order"){
            $sql = "select count(id) storeitemNum from uuch_storeitem where dateInStore >= '".$start."' AND dateInStore <= '".$end."' AND isdelete != 1
                        and userid in (SELECT userid from uuch_storeitem where  dateInStore < '".$start."' GROUP BY userid)";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
        
    }
    
    /**
     * $start 开始时间
     * $end  结束时间
     * $type  "all" 所有用户 "new" 新用户 "order" 老用户 
     * $cid   所在国家
     * 包裹入库重量
     */
    public function instoreWeight($start,$end,$type,$cid = null){
        if($type == "all"){
            $sql = "select sum(weight)/1000 from uuch_storeitem 
                where dateInStore >= '".$start."' AND dateInStore <= '".$end."' AND isdelete != 1";
        }else if($type == "new"){
            if($cid){
                $sql = "select sum(weight)/1000 from uuch_storeitem s left join uuch_user u on s.userid = u.id where s.dateInstore >=  '".$start."' AND s.dateInStore <= '".$end."' AND s.isdelete != 1 AND u.cityId = ".$cid."
                    AND s.userid not in (SELECT s.userid from uuch_storeitem s where s.dateInstore < '".$start."' GROUP BY s.userid)";
            }else{
                $sql = "select sum(weight)/1000 from uuch_storeitem where dateInStore >= '".$start."' AND dateInStore <= '".$end."' AND isdelete != 1
                    and userid not in (SELECT userid from uuch_storeitem where  dateInStore < '".$start."' GROUP BY userid)";
            }
        }else if($type == "order"){
            $sql = "select sum(weight)/1000 from uuch_storeitem where dateInStore >= '".$start."' AND dateInStore <= '".$end."' AND isdelete != 1
                and userid in (SELECT userid from uuch_storeitem where  dateInStore < '".$start."' GROUP BY userid)";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    /**
     * $start 开始时间
     * $end  结束时间
     * $type  "all" 所有用户 "new" 新用户 "order" 老用户 
     * $cid   所在国家
     * 发国际运单次数
     */
    public function sendBillCount($start,$end,$type,$cid = null){
        if($type == "all"){
            $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."'";
        }else if($type == "new"){
            if($cid){
                $sql = "select count(w.id) orderNum  from uuch_waybill w left join uuch_user u on w.userId = u.id where w.status >=1 and w.dateCreated >= '".$start."' AND w.dateCreated <= '".$end."' and u.cityId = ".$cid."
                    and w.userId not in (SELECT w.userId from uuch_waybill w where w.status>=1 and w.dateCreated < '".$start."' GROUP BY w.userId)";
            }else{
                $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."'
                    and userId not in (SELECT userId from uuch_waybill where status>=1 and dateCreated < '".$start."' GROUP BY userId)";
            }
        }else if($type == "order"){
            $sql = "select count(id) orderNum  from uuch_waybill where status >=1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."'
                    and userId in (SELECT userId from uuch_waybill where status>=1 and dateCreated < '".$start."' GROUP BY userid)";
        }
        
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    /**
     * $start 开始时间
     * $end  结束时间
     * $type  "all" 所有用户 "new" 新用户 "order" 老用户 
     * 发国际运单金额
     */
    public function sendBillMoney($start,$end,$type,$cid = null){
        if($type == "all"){
            $sql = "select sum(SHIPMONEY)  from uuch_waybill where status >=1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."'";
        }else if($type == "new"){
            if($cid){
                $sql = "select sum(SHIPMONEY)  from uuch_waybill w left join uuch_user u on w.userId = u.id where w.status >= 1 and w.dateCreated >= '".$start."' AND w.dateCreated <= '".$end."' and u.cityId = ".$cid."
                    and w.userId not in (SELECT w.userId from uuch_waybill w where w.status>=1 and w.dateCreated < '".$start."' GROUP BY w.userid)";
            }else{
                $sql = "select sum(SHIPMONEY)  from uuch_waybill where status >=1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."'
                    and userId not in (SELECT userId from uuch_waybill where status>=1 and dateCreated < '".$start."' GROUP BY userid)";
            }
        }else if($type == "order"){
            $sql = "select sum(SHIPMONEY)  from uuch_waybill where status >=1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."'
                        and userId in (SELECT userId from uuch_waybill where status>=1 and dateCreated < '".$start."' GROUP BY userid)";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    } 
    
    /**
     * $start 开始时间
     * $end  结束时间
     * $type  "all" 所有用户 "new" 新用户 "order" 老用户 
     * 国际运单重量
     */
    public function sendBillWeight($start,$end,$type){
        if($type == "all"){
            $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."'";
        }else if($type == "new"){
            $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."'
                    and userId not in (select userId from uuch_waybill where dateCreated < '".$start."' GROUP BY userId )";
        }else if($type == "order"){
            $sql = "SELECT SUM(CASE WHEN isVolume=1 THEN volumeWeight ELSE productWeight+bagWeight END)/1000 FROM `uuch_waybill` 
                    where status >=1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."'
                    and userId in (select userId from uuch_waybill where dateCreated < '".$start."' GROUP BY userId )";
        }else if($type == "weight"){
            $sql = "SELECT SUM(productWeight+bagWeight)/1000 FROM `uuch_waybill` 
                    where status >=1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."'";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    
    /**
     * $start 开始时间
     * $end  结束时间
     * $type  "all" 所有用户 "new" 新用户 "order" 老用户 
     * $cid 所在国家
     * 发运单会员数
     */
    public function sendBillMemberCount($start,$end,$type,$cid = null){
        if($type == "all"){
            $sql = "select count(*) as memberCount from (select count(w.id) from uuch_waybill w 
                where status >= 1 and dateCreated >= '".$start."' AND dateCreated <= '".$end."' group by userId) as bill";
        }else if($type == "order"){
            $sql = "SELECT count(*) as memberCount from (SELECT count(w.id) FROM uuch_waybill w 
                WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."' 
                AND userId IN (SELECT userId From uuch_waybill where status >= 1 and dateCreated < '".$start."' GROUP BY userid) GROUP BY userId) as bill";
        }else if($type === "new"){
            if($cid){
                $sql = "SELECT count(*) as memberCount from (SELECT count(w.id) FROM uuch_waybill w left join uuch_user u on u.id = w.userId  
                    WHERE w.status >= 1 AND w.dateCreated >= '".$start."' AND w.dateCreated <= '".$end."' and u.cityId = ".$cid." 
                    AND w.userId NOT IN (SELECT w.userId From uuch_waybill w where w.status >= 1 and w.dateCreated < '".$start."' GROUP BY w.userid) GROUP BY w.userId) as bill";
            }else{
                $sql = "SELECT count(*) as memberCount from (SELECT count(w.id) FROM uuch_waybill w 
                    WHERE status >= 1 AND dateCreated >= '".$start."' AND dateCreated <= '".$end."' 
                    AND userId NOT IN (SELECT userId From uuch_waybill where status >= 1 and dateCreated < '".$start."' GROUP BY userid) GROUP BY userId) as bill";
            }
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    /**
     * $start 开始时间
     * $end  结束时间
     * 上门取件订单数
     */
    public function visitingCount($start,$end){
        $sql = "select count(id) visitingCount from uuch_visitingServer 
                    where dateCreated >= '".$start."' AND dateCreated <= '".$end."' AND (isDel is null or isDel = '0')";
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    /**
     * $start 开始时间
     * $end  结束时间
     * 上门取件入库数
     */
    public function visitingInstoreCount($start,$end){
        $sql = "select count(distinct Logistics) storeitemNum from uuch_storeitem 
                    where intype like '%上门%' and dateInStore >= '".$start."' AND dateInStore <= '".$end."' AND interior>=0 AND (isdelete is null or isdelete = '0')";
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    /**
     * 获取当前总会员数
     */
    public function getMemberCount(){
        $sql = "select count(*) as memberCount from uuch_user where userType is null or userType = '0' or userType = ''";
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    /**
     * $type = 1  当前库存
     * $type = 2  昨天库存
     * 获取库存重量
     */
    public function getStoreWeight($type){
        if($type == 1){
            $sql = "select sum(weight)/1000 from uuch_storeitem where isdelete != 1 and interior in (0,1)";
        }else if($type == 2){
            $sql = "select sum(weight)/1000 from uuch_storeitem where isdelete != 1 and interior in (0,1) and dateInstore<=date_add(curdate(),interval -1 day)";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    public function getAllBalance($type,$start,$end){
        if($type == "recharge"){
            $sql = "select sum(afterMoney - beforeMoney) from uuch_account_history where afterMoney > beforeMoney and dateCreated >= '".$start."' and dateCreated <= '".$end."' and type = 2 and state = 1";
        }else if($type == "expense"){
            $sql = "select sum(beforeMoney - afterMoney) from uuch_account_history where afterMoney < beforeMoney and dateCreated >= '".$start." 23:59:59' and dateCreated <= '".$end."' and type = 1 and state = 1";
        }else if($type == "balance"){
            $sql = "select sum(money) as balance from uuch_account";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }
    
    public function OrderData($type, $dataTime) {
        if($type == "all") {
            $sql = "SELECT * FROM `uuch_order` where datePaid >= '".$dataTime."' and datePaid <= '".$dataTime." 23:59:59' and status not in (0,10,11,12) and isdelete != 1";
        } else if ($type == "new") {
            $sql = "select * from `uuch_order` where datePaid >= '".$dataTime."' and datePaid <= '".$dataTime." 23:59:59' and status not in (0,10,11,12) and isdelete != 1 and ";
            $sql .= "userid not in (select userid from uuch_order where datePaid < '".$dataTime."' and status not in (0,10,11,12) and isdelete != 1)";
        } else if ($type == "old") {
            $sql = "select * from `uuch_order` where datePaid >= '".$dataTime."' and datePaid <= '".$dataTime." 23:59:59' and status not in (0,10,11,12) and isdelete != 1 and ";
            $sql .= "userid in (select userid from uuch_order where datePaid < '".$dataTime."' and status not in (0,10,11,12) and isdelete != 1)";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchAll();
    }
    
    public function WayData($type, $dataTime) {
        if($type == "all") {
            $sql = "SELECT id FROM `uuch_waybill` where datepaid >= '".$dataTime."' and datePaid <= '".$dataTime." 23:59:59' and status > 0 and (problem is null or problem !=3)";
        } else if ($type == "new") {
            $sql = "SELECT id FROM `uuch_waybill` where datepaid >= '".$dataTime."' and datePaid <= '".$dataTime." 23:59:59' and status > 0 and (problem is null or problem !=3) and ";
            $sql .= "userid not in (select userid from `uuch_waybill` where datepaid < '".$dataTime."' and status > 0 and (problem is null or problem !=3))";
        } else if ($type == "old") {
            $sql = "SELECT id FROM `uuch_waybill` where datepaid >= '".$dataTime."' and datePaid <= '".$dataTime." 23:59:59' and status > 0 and (problem is null or problem !=3) and ";
            $sql .= "userid in (select userid from `uuch_waybill` where datepaid < '".$dataTime."' and status > 0 and (problem is null or problem !=3))";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchAll();
    }
    
    public function StoreData($type, $dataTime) {
        if($type == "all") {
            $sql = "SELECT weight,userid FROM `uuch_storeitem` where dateInStore >= '".$dataTime."' and dateInStore <= '".$dataTime." 23:59:59' and (isdelete is null or isdelete != 1)";
        } else if ($type == "new") {
            $sql = "SELECT weight,userid FROM `uuch_storeitem` where dateInStore >= '".$dataTime."' and dateInStore <= '".$dataTime." 23:59:59' and (isdelete is null or isdelete != 1) and ";
            $sql .= "userid not in (select userid from `uuch_storeitem` where dateInStore < '".$dataTime."' and (isdelete is null or isdelete != 1))";
        } else if ($type == "old") {
            $sql = "SELECT weight,userid FROM `uuch_storeitem` where dateInStore >= '".$dataTime."' and dateInStore <= '".$dataTime." 23:59:59' and (isdelete is null or isdelete != 1) and ";
            $sql .= "userid in (select userid from `uuch_storeitem` where dateInStore < '".$dataTime."' and (isdelete is null or isdelete != 1))";
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchAll();
    }
    
    public function distinctState($type,$startTime,$entTime) {
        if($type == "way") {
            $sql = "SELECT DISTINCT other FROM `uuch_data` where dataTime >= '".$startTime."' and dataTime <= '".$entTime."' and other != 'all' and objectType = ".Application_Model_Data::Type_Way;
        } else if($type == "order") {
            $sql = "SELECT DISTINCT other FROM `uuch_data` where dataTime >= '".$startTime."' and dataTime <= '".$entTime."' and other != 'all' and objectType = ".Application_Model_Data::Type_Order;
        } else if($type == "store") {
            $sql = "SELECT DISTINCT other FROM `uuch_data` where dataTime >= '".$startTime."' and dataTime <= '".$entTime."' and other != 'all' and objectType = ".Application_Model_Data::Type_Store;
        } else if($type == "user") {
            $sql = "SELECT DISTINCT other FROM `uuch_data` where dataTime >= '".$startTime."' and dataTime <= '".$entTime."' and other != 'all' and objectType = ".Application_Model_Data::Type_User;
        }
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchAll();
    }
}

?>
